import { useRequest } from 'umi';
import { createModel } from 'hox';
import { useRef } from 'react';
import { ActionType } from '@/components/ProTable';
import {
  queryRunAlarmAPI,
  queryRunAlarmChartAPI,
  queryRunAlarmPieAPI,
  queryHisAlarmChartAPI,
  queryHisAlarmAPI,
  queryHisAlarmPieAPI,
  confirmAlarmAPI,
  cancelAlarmAPI,
  endAlarmAPI,
  queryRunAlarmCountAPI,
} from './services';

function useHoxModel() {
  const realtimeActionRef = useRef<ActionType>();
  //告警
  //获取实时告警表格
  const { run: getRunAlarm } = useRequest(queryRunAlarmAPI, { manual: true });
  //获取实时告警图表
  const { run: getRunAlarmChart, data: runAlarmChart, loading: runAlarmChartLoading } = useRequest(
    queryRunAlarmChartAPI,
    {
      manual: true,
    },
  );

  //获取实时告警饼图图表
  const { run: getRunAlarmPie, data: runAlarmPie, loading: runAlarmPieLoading } = useRequest(
    queryRunAlarmPieAPI,
    {
      manual: true,
    },
  );
  //获取历史告警表格
  const { run: getHisAlarm } = useRequest(queryHisAlarmAPI, { manual: true });
  //取消告警
  const { run: cancelAlarm } = useRequest(cancelAlarmAPI, {
    manual: true,
    formatResult: (res) => res,
  });
  //结束告警
  const { run: endAlarm } = useRequest(endAlarmAPI, {
    manual: true,
    formatResult: (res) => res,
  });
  //确认告警
  const { run: confirmAlarm } = useRequest(confirmAlarmAPI, {
    manual: true,
    formatResult: (res) => res,
  });
  //获取实时告警图表
  const { run: getHisAlarmChart, data: hisAlarmChart, loading: hisAlarmChartLoading } = useRequest(
    queryHisAlarmChartAPI,
    {
      manual: true,
    },
  );
  //获取实时告警饼图图表
  const { run: getRunAlarmCount, data: runAlarmCount } = useRequest(queryRunAlarmCountAPI, {
    manual: true,
  });

  //获取实时告警饼图图表
  const { run: getHisAlarmPie, data: hisAlarmPie, loading: hisAlarmPieLoading } = useRequest(
    queryHisAlarmPieAPI,
    {
      manual: true,
    },
  );

  return {
    getRunAlarmCount,
    runAlarmCount,
    getRunAlarm,
    getRunAlarmChart,
    runAlarmChart,
    runAlarmChartLoading,
    getRunAlarmPie,
    runAlarmPie,
    realtimeActionRef,
    runAlarmPieLoading,
    getHisAlarm,
    getHisAlarmChart,
    hisAlarmChart,
    hisAlarmChartLoading,
    getHisAlarmPie,
    hisAlarmPie,
    hisAlarmPieLoading,
    confirmAlarm,
    cancelAlarm,
    endAlarm,
  };
}
export default createModel(useHoxModel);
